package com.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.item.mapper.VehicleMapper;
import com.item.pojo.Vehicle;
import com.item.service.VehicleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> implements VehicleService {

    @Override
    public Map<String, Object> getQueryPage(String styleType, Integer state, Integer store, Integer page, Integer limit) {
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(page, limit);
        PageHelper.orderBy("vid desc");
        List<Vehicle> data = super.baseMapper.getQueryPage(styleType, state, store);
        PageInfo<Vehicle> pageInfo = new PageInfo<>(data);
        long total = pageInfo.getTotal();
        map.put("code", 0);
        map.put("count", total);
        map.put("data", data);
        return map;
    }
}
